<script lang="ts" setup>
import tzLoading from '@/components/tz-loading.vue'


const appStore = useAppStore()

const tableData = ref([])
const loading = ref(true)


// search
const searchForm = reactive({
  time: [],
  equipmentid: '',
  projectid: '',
  tEquipmentControllerid: 0
})

const optionloading = ref(true)
const projectoptions = ref([])
const equipmentoptions = ref([])


// 获取项目列表
const getprojectData = () => {
  tProjectControllerSellist().then(res => {
    let T = [{
      value: '',
      label: '全部',
    }]
    let B = res.result.map(v => {
      return {
        value: v.id,
        label: v.name,
      }
    })

    projectoptions.value = B
    if (projectoptions.value.length > 0) {
      searchForm.projectid = B[0].value
      getData()
    }

  })
}

getprojectData()

// 获取设备列表
const getequipmentData = () => {
  optionloading.value = true
  searchForm.equipmentid = ''
  equipmentoptions.value = []
  if (searchForm.projectid == '') return
  tProjectControllerSelequipmentbyid(searchForm.projectid).then(res => {
    equipmentoptions.value = res.result.map(v => {
      return {
        value: v.id,
        label: v.equipmentid,
      }
    })
  }).finally(() => {
    optionloading.value = false
  })
}



// 分页
const pageSize4 = ref(10)
const currentPage4 = ref(1)
const total = ref(0)
const size = ref<ComponentSize>('default')
const disabled = ref(false)
const background = ref(false)

const handleSizeChange = (val: number) => {
  getData()
}
const handleCurrentChange = (val: number) => {
  getData()
}


const getData = () => {
  console.log(searchForm)
  loading.value = true
  let Q = {
    "endtime": searchForm.time.length > 0 ? searchForm.time[1] : '',
    "equipmentid": searchForm.equipmentid,
    "index": currentPage4.value,
    "projectid": searchForm.projectid,
    "size": pageSize4.value,
    "starttime": searchForm.time.length > 0 ? searchForm.time[0] : '',
    "qttype": searchForm.tEquipmentControllerid
  }
  let fn
  switch (searchForm.tEquipmentControllerid) {
    case 0:
      fn = tdatahistoryControllerSelkldbypage
      break;
    case 1:
      fn = tdatahistoryControllerSelifv5bypage
      break;
    case 2:
      fn = tdatahistoryControllerSelcmcbypage
      break;
    case 3:
      fn = tdatahistoryControllerSeljsmlbypage
      break;
    case 4:
      fn = tdatahistoryControllerSeloilsbypage
      break;
    case 5:
      fn = tdatahistoryControllerSelredbirdbypage
      break;
    case 6:
      fn = tdatahistoryControllerSeltortoisebypage
      break;
    case 7:
      fn = tdatahistoryControllerSeljsmlbigbypage
      break;
    default:
      fn = tdatahistoryControllerSelqtbypage
      break;

  }



  fn(Q).then(res => {
    total.value = res.page.total
    tableData.value = res.result
  }).finally(() => loading.value = false)
}

getData()


const changeTe = (e) => {
  currentPage4.value = 1
  getData()
}

</script>

<template>
  <tzLoading v-if="loading"></tzLoading>

  <div class="flex flex-col flex-1 overflow-auto" v-else>
    <div class="h-[13%]"></div>
    <div class="px-[25px] flex gap-[20px]">



      <el-form-item label="传感器">
        <el-select @change="changeTe" v-model="searchForm.tEquipmentControllerid" placeholder="请选择传感器类型" style="">
          <el-option v-for="item in appStore.tEquipmentControllerList" :key="item.value" :label="item.label"
            :value="item.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="日期">
        <el-date-picker v-model="searchForm.time" type="daterange" range-separator="To" start-placeholder="Start date"
          end-placeholder="End date" placeholder="请选择日期" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
      </el-form-item>

      <el-form-item label="项目">
        <el-select v-model="searchForm.projectid" placeholder="请选择项目" @change="getequipmentData()">
          <el-option v-for="item in projectoptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="设备">
        <el-select v-model="searchForm.equipmentid" placeholder="请选择设备" style="">
          <el-option v-for="item in equipmentoptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>





      <el-button @click="getData" class="w-[90px] ml-auto  flex justify-center items-center" color="#0c9bc8">
        <span class="text-[16px] font-medium text-white">查询</span>
      </el-button>

    </div>
    <div class="flex-1 p-[25px] overflow-auto">
      <el-table :data="tableData" class="" style="width: 100%;height: 100%;">

        <template v-if="searchForm.tEquipmentControllerid == 0">
          <el-table-column prop="name" label="设备名称"></el-table-column>

          <el-table-column prop="grade1" label="通道1"></el-table-column>
          <el-table-column prop="grade2" label="通道2"></el-table-column>
          <el-table-column prop="grade3" label="等通3"></el-table-column>
          <el-table-column prop="grade4" label="通道4"></el-table-column>
          <el-table-column prop="grade5" label="通道5"></el-table-column>
          <el-table-column prop="grade6" label="通道6"></el-table-column>
          <el-table-column prop="gradeall" label="污染度等级"></el-table-column>
          <el-table-column prop="standard" label="标准"></el-table-column>
          <el-table-column prop="isalarm" label="告警">
            <template #default="scope">
              <div class="flex gap-[10px]">
                <el-tag :type="scope.row.isalarm == 1 ? 'danger' : 'success'">{{ scope.row.isalarm == 1 ? '告警' : '未告警'
                }}</el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="ybzt" label="油泵状态">
            <template #default="scope">
              <div class="flex gap-[10px]">
                <el-tag :type="scope.row.ybzt == 1 ? 'success' : 'danger'">{{ scope.row.ybzt == 1 ? '开启' : '关闭'
                }}</el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="创建时间"></el-table-column>
        </template>


        <template v-if="searchForm.tEquipmentControllerid == 1">
          <el-table-column prop="name" label="设备名称"></el-table-column>
          <!-- <el-table-column prop="conductivity" label="电导率"></el-table-column> -->
          <el-table-column prop="density" label="密度"></el-table-column>
          <el-table-column prop="dielectricConstant" label="介电常数"></el-table-column>
          <el-table-column prop="dynamicViscosity" label="动力粘度"></el-table-column>
          <el-table-column prop="moisture" label="湿度"></el-table-column>
          <el-table-column prop="temperature" label="温度"></el-table-column>
          <el-table-column prop="tan" label="酸值KOH/mg"></el-table-column>
          <el-table-column prop="viscosity100" label="粘度100"></el-table-column>
          <el-table-column prop="viscosity40" label="粘度40"></el-table-column>
          <el-table-column prop="water" label="水分ppm"></el-table-column>

          <el-table-column prop="isalarm" label="告警">
            <template #default="scope">
              <div class="flex gap-[10px]">
                <el-tag :type="scope.row.isalarm == 1 ? 'danger' : 'success'">{{ scope.row.isalarm == 1 ? '告警' : '未告警'
                }}</el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="alarmlevel" label="告警等级"></el-table-column>

          <el-table-column prop="createTime" label="创建时间"></el-table-column>
        </template>



        <template v-if="searchForm.tEquipmentControllerid == 2">
          <el-table-column prop="name" label="设备名称"></el-table-column>
          <el-table-column prop="bdvEst" label="bdv 估计"></el-table-column>
          <el-table-column prop="contamination30" label="污染(30min的均值)"></el-table-column>
          <el-table-column prop="degradation30" label="劣化(30min的均值)"></el-table-column>
          <el-table-column prop="epsilonRMeas" label="相对介电常数测量"></el-table-column>
          <el-table-column prop="epsilonRTc" label="相对介电常数补偿"></el-table-column>
          <el-table-column prop="ht" label="ht"></el-table-column>
          <el-table-column prop="kappaMeas" label="电导率pS/m"></el-table-column>
          <el-table-column prop="kappaTc" label="电导率补偿pS/m"></el-table-column>
          <el-table-column prop="lt1" label="lt1"></el-table-column>
          <el-table-column prop="st" label="st"></el-table-column>
          <el-table-column prop="statusCode" label="状态码"></el-table-column>
          <el-table-column prop="t" label="t"></el-table-column>
          <el-table-column prop="tan" label="酸值KOH/mg"></el-table-column>
          <el-table-column prop="tan30" label="酸值(30min的均值)KOH/mg"></el-table-column>
          <el-table-column prop="tanDeltaMeas" label="tan delta 测量"></el-table-column>
          <el-table-column prop="tanDeltaTc" label="tan delta 补偿"></el-table-column>
          <el-table-column prop="temerature" label="温度"></el-table-column>
          <el-table-column prop="waEst" label="wa 估计"></el-table-column>
          <el-table-column prop="water" label="水分"></el-table-column>
          <el-table-column prop="water30" label="水分(30min的均值)ppm"></el-table-column>
          <el-table-column prop="wsi" label="wsi"></el-table-column>
          <el-table-column prop="wsi30" label="Wsi(30min的均值)"></el-table-column>
          <el-table-column prop="isalarm" label="告警">
            <template #default="scope">
              <div class="flex gap-[10px]">
                <el-tag :type="scope.row.isalarm == 1 ? 'danger' : 'success'">{{ scope.row.isalarm == 1 ? '告警' : '未告警'
                }}</el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="alarmlevel" label="告警等级"></el-table-column>

          <el-table-column prop="createTime" label="创建时间"></el-table-column>
        </template>




        <template v-else-if="searchForm.tEquipmentControllerid == 3">
          <el-table-column prop="name" label="设备名称"></el-table-column>
          <!-- <el-table-column prop="address" label="从机地址"></el-table-column>
          <el-table-column prop="baudrate" label="波特率"></el-table-column> -->

          <el-table-column prop="ferromagnetic30to50" label="铁磁30-50um"></el-table-column>
          <el-table-column prop="ferromagnetic50to100" label="铁磁铁磁50-100um"></el-table-column>

          <el-table-column prop="ferromagnetic100to200" label="铁磁100-200um"></el-table-column>
          <el-table-column prop="ferromagnetic200to400" label="铁磁200-400um"></el-table-column>
          <el-table-column prop="ferromagnetic400to800" label="铁磁400-800um"></el-table-column>
          <el-table-column prop="ferromagnetic800plus" label="铁磁大于800um"></el-table-column>
          <el-table-column prop="ferromagnetic24H" label="铁磁24H总数"></el-table-column>

          <el-table-column prop="ferromagneticND" label="铁磁浓度"></el-table-column>
          <el-table-column prop="ferromagneticall" label="铁磁磨粒总数"></el-table-column>






          <el-table-column prop="flow" label="流量"></el-table-column>

          <el-table-column prop="isalarm" label="告警">
            <template #default="scope">
              <div class="flex gap-[10px]">
                <el-tag :type="scope.row.isalarm == 1 ? 'danger' : 'success'">{{ scope.row.isalarm == 1 ? '告警' : '未告警'
                }}</el-tag>
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="nonferromagnetic120to200" label="非铁磁120-200um"></el-table-column>
          <el-table-column prop="nonferromagnetic200to400" label="非铁磁200-400um"></el-table-column>
          <el-table-column prop="nonferromagnetic400to800" label="非铁磁400-800um"></el-table-column>
          <el-table-column prop="nonferromagnetic800to1600" label="非铁磁800-1600um"></el-table-column>
          <el-table-column prop="nonferromagnetic1600plus" label="非铁磁大于1600um"></el-table-column>

          <el-table-column prop="nonferromagnetic24H" label="非铁磁24H"></el-table-column>


          <el-table-column prop="nonferromagneticND" label="非铁磁浓度"></el-table-column>

          <el-table-column prop="nonferromagneticall" label="非铁磁总数"></el-table-column>


          <el-table-column prop="alarmlevel" label="告警等级"></el-table-column>




          <el-table-column prop="createTime" label="创建时间"></el-table-column>
        </template>


        <template v-else-if="searchForm.tEquipmentControllerid == 4">
          <el-table-column prop="name" label="设备名称"></el-table-column>
          <el-table-column prop="pressure" label="压力"></el-table-column>


          <el-table-column prop="isalarm" label="告警">
            <template #default="scope">
              <div class="flex gap-[10px]">
                <el-tag :type="scope.row.isalarm == 1 ? 'danger' : 'success'">{{ scope.row.isalarm == 1 ? '告警' : '未告警'
                }}</el-tag>
              </div>
            </template>
          </el-table-column>

          <!-- <el-table-column prop="type" label="状态">
            <template #default="scope">
              <div class="flex gap-[10px]">
                <el-tag :type="scope.row.type == 1 ? 'success' : 'danger'">{{ scope.row.type == 1 ? '开机' : '关机'
                }}</el-tag>
              </div>
            </template>
          </el-table-column> -->

          <el-table-column prop="alarmlevel" label="告警等级"></el-table-column>

          <el-table-column prop="createTime" label="创建时间"></el-table-column>
        </template>


        <template v-else-if="searchForm.tEquipmentControllerid == 5">
          <el-table-column prop="name" label="设备名称"></el-table-column>


          <el-table-column prop="dielectricconstant" label="介电常数"></el-table-column>
          <el-table-column prop="dielectricconstanttc" label="介电常数补偿值"></el-table-column>
          <el-table-column prop="fonductivity" label="电导率"></el-table-column>
          <el-table-column prop="fonductivitytc" label="电导率补偿值"></el-table-column>
          <el-table-column prop="tan" label="酸值"></el-table-column>
          <el-table-column prop="temperature" label="温度"></el-table-column>
          <el-table-column prop="hsl" label="含水率"></el-table-column>
          <el-table-column prop="water" label="水分"></el-table-column>
          <el-table-column prop="ypsm" label="油品寿命"></el-table-column>

          <el-table-column prop="isalarm" label="告警">
            <template #default="scope">
              <div class="flex gap-[10px]">
                <el-tag :type="scope.row.isalarm == 1 ? 'danger' : 'success'">{{ scope.row.isalarm == 1 ? '告警' : '未告警'
                }}</el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="alarmlevel" label="告警等级"></el-table-column>

          <el-table-column prop="createTime" label="创建时间"></el-table-column>
        </template>


        <template v-else-if="searchForm.tEquipmentControllerid == 6">
          <el-table-column prop="name" label="设备名称"></el-table-column>


          <el-table-column prop="dielectricconstant" label="介电常数"></el-table-column>
          <el-table-column prop="dielectricconstanttc" label="介电常数补偿值"></el-table-column>
          <el-table-column prop="fonductivity" label="电导率"></el-table-column>
          <el-table-column prop="fonductivitytc" label="电导率补偿值"></el-table-column>
          <el-table-column prop="hsl" label="含水率"></el-table-column>
          <el-table-column prop="temperature" label="温度"></el-table-column>
          <el-table-column prop="jcdy" label="击穿电压"></el-table-column>
          <el-table-column prop="ypsm" label="油品寿命"></el-table-column>

          <el-table-column prop="isalarm" label="告警">
            <template #default="scope">
              <div class="flex gap-[10px]">
                <el-tag :type="scope.row.isalarm == 1 ? 'danger' : 'success'">{{ scope.row.isalarm == 1 ? '告警' : '未告警'
                }}</el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="alarmlevel" label="告警等级"></el-table-column>

          <el-table-column prop="createTime" label="创建时间"></el-table-column>
        </template>



        <template v-else-if="searchForm.tEquipmentControllerid == 7">
          <el-table-column prop="name" label="设备名称"></el-table-column>
          <el-table-column prop="ferromagnetic40to99" label="铁磁40-99um"></el-table-column>

          <el-table-column prop="ferromagnetic100to199" label="铁磁100-199um"></el-table-column>
          <el-table-column prop="ferromagnetic200to299" label="铁磁200-299um"></el-table-column>
          <el-table-column prop="ferromagnetic300to399" label="铁磁300-399um"></el-table-column>
          <el-table-column prop="ferromagnetic400plus" label="铁磁>400um"></el-table-column>
          <el-table-column prop="ferromagneticall" label="铁磁磨粒总数"></el-table-column>


          <el-table-column prop="flow" label="流量"></el-table-column>

          <el-table-column prop="isalarm" label="告警">
            <template #default="scope">
              <div class="flex gap-[10px]">
                <el-tag :type="scope.row.isalarm == 1 ? 'danger' : 'success'">{{ scope.row.isalarm == 1 ? '告警' : '未告警'
                }}</el-tag>
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="nonferromagnetic150to199" label="非铁磁150-199um"></el-table-column>
          <el-table-column prop="nonferromagnetic200to299" label="非铁磁200-299um"></el-table-column>
          <el-table-column prop="nonferromagnetic300to399" label="非铁磁300-399um"></el-table-column>
          <el-table-column prop="nonferromagnetic400to499" label="非铁磁400-499um"></el-table-column>

          <el-table-column prop="nonferromagnetic500plus" label="非铁磁>500um"></el-table-column>
          <el-table-column prop="nonferromagneticall" label="非铁磁磨粒总数"></el-table-column>
          <el-table-column prop="qntemperature" label="壳内温度"></el-table-column>

          <el-table-column prop="temperature" label="温度℃"></el-table-column>
          <el-table-column prop="viscosity" label="粘度Pa·s"></el-table-column>
          <el-table-column prop="water" label="含水量mg/L"></el-table-column>
          <el-table-column prop="waterhuo" label="水活性aw"></el-table-column>
          <el-table-column prop="density" label="密度g/L"></el-table-column>
          <el-table-column prop="dielectricconstant" label="介电常数"></el-table-column>
          <el-table-column prop="alarmlevel" label="告警等级"></el-table-column>

          <el-table-column prop="createTime" label="创建时间"></el-table-column>
        </template>



        <template v-else>
          <el-table-column prop="name" label="设备名称"></el-table-column>
          <el-table-column prop="equipmentid" label="设备编号"></el-table-column>
          <el-table-column prop="id" label="设备id"></el-table-column>
          <el-table-column prop="isalarm" label="告警">
            <template #default="scope">
              <div class="flex gap-[10px]">
                <el-tag :type="scope.row.isalarm == 1 ? 'danger' : 'success'">{{ scope.row.isalarm == 1 ? '告警' : '未告警'
                }}</el-tag>
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="value" label="测量值"></el-table-column>
          <el-table-column prop="yl1" label="预留一"></el-table-column>
          <el-table-column prop="yl2" label="预留二"></el-table-column>
          <el-table-column prop="yl3" label="预留三"></el-table-column>
          <el-table-column prop="createtime" label="创建时间"></el-table-column>
        </template>




      </el-table>
    </div>
    <div class="flex justify-center mb-[20px]">
      <el-pagination v-model:current-page="currentPage4" v-model:page-size="pageSize4" :page-sizes="[10, 20, 50, 100]"
        :size="size" :disabled="disabled" :background="background" layout="total, sizes, prev, pager, next, jumper"
        :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>





  </div>
</template>

<style scoped>
:deep(.el-table__row) {
  background-color: #f3fdf1;
}

:deep(th>.el-table__cell) {
  background-color: #0f914c;
}

:deep(.el-table th.el-table__cell) {
  background-color: #0e904c;
}


:deep(.el-table th.el-table__cell .cell) {
  color: #fff;
}
</style>
